package com.graph.similar;

import java.util.HashSet;
import java.util.Set;

/**
 * @author LiWu
 * Created on 2018/1/17.
 */
public class JackcardSimilar {

    public static double calJackcardSim(Set<String> s1, Set<String> s2) {
        Set<String> all = new HashSet<>();
        all.addAll(s1);
        all.addAll(s2);
        Set<String> both = new HashSet<>();
        both.addAll(s1);
        both.retainAll(s2);
        return (double) both.size() / all.size();
    }

    public static void main(String[] args) {
        Set<String> s1 = new HashSet<String>();
        s1.add("互联网");
        s1.add("金融");
        s1.add("房产");
        s1.add("融资");
        s1.add("科技");
        Set<String> s2 = new HashSet<String>();
        s2.add("互联网");
        s2.add("开源");
        s2.add("人工智能");
        s2.add("软件");
        s2.add("科技");
        s2.add("房产");
        System.out.println(calJackcardSim(s1, s2));
    }
}
